package com.bootdo.per.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

import com.bootdo.per.dao.ScoreDao;
import com.bootdo.per.domain.ScoreDO;
import com.bootdo.per.service.ScoreService;



@Service

public class ScoreServiceImpl implements ScoreService {
	@Autowired
	private ScoreDao scoreDao;
	
	@Override
	public ScoreDO get(Long id){
		return scoreDao.get(id);
	}
	
	@Override
	public List<Map<String, Object>> list(Map<String, Object> map){
		switch ((String)map.get("type")) {
			case "year":
				return scoreDao.listByYear(map);
			case "quarter":
						
				return scoreDao.listByQuarter(map);
			case "month":
				return scoreDao.listByMonth(map);
		}
		return null;
	}
	
	@Override
	public int count(Map<String, Object> map){
		switch ((String)map.get("type")) {
			case "year":
				return scoreDao.listByYearCount(map);
			case "quarter":
						
				return scoreDao.listByQuarterCount(map);
			case "month":
				return scoreDao.listByMonthCount(map);
			}
			return 0;
	}
	
	@Override
	public int save(ScoreDO score){
		return scoreDao.save(score);
	}
	
	@Override
	public int update(ScoreDO score){
		return scoreDao.update(score);
	}
	
	@Override
	public int remove(Long id){
		return scoreDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return scoreDao.batchRemove(ids);
	}

	@Override
	@Transactional
	public int saveResult(List<Map<String, Object>> List, Map<String, Object> map) {
		try{
			scoreDao.delete(map);
			return scoreDao.saveResult(List);
		}catch (Exception e) {
			return 0;
		}
	}

	/**
	 * 根据年份得到团队名
	 */
	@Override
	public List<String> getTeamByYear(Integer year) {
		return scoreDao.getTeamByYear(year);
	}

	/**
	 * 根据团队名得到所有团队的分数
	 */
	@Override
	public List<ScoreDO> listTeamScore(String name) {
		return scoreDao.listTeamScore(name);
	}

	/**
	 * 根据部门和年份得到所有团队的团队名
	 */
	@Override
	public List<String> getTeamByDept(Map<String, Object> map) {
		return scoreDao.getTeamByDept(map);
	}

	/**
	 * 根据年份得到员工姓名
	 */
	@Override
	public List<String> getPersonByYear(Integer year) {
		return scoreDao.getPersonByYear(year);
	}

	/**
	 * 根据员工姓名得到所有人的分数
	 */
	@Override
	public List<ScoreDO> listPersonScore(String name) {
		return scoreDao.listPersonScore(name);
	}

	/**
	 * 根据部门和年份得到所有员工的姓名
	 */
	@Override
	public List<String> getPersonByDept(Map<String, Object> map) {
		return scoreDao.getPersonByDept(map);
	}
	
}
